//
//  MyPrivacySettingVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/9/13.
//

#import "MyPrivacySettingVC.h"
#import "MyPrivacySettingCell.h"

@interface MyPrivacySettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic)UITableView * my_setting_tableView;
@property (strong, nonatomic)NSArray * my_settingArr;
@end

@implementation MyPrivacySettingVC

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"隐私设置";
    self.my_settingArr = @[@{@"titleName":@"关注和粉丝列表",@"subtitleName":@"开启隐私后，仅自己可见，其它人将不能访问关注和粉丝列表",@"imgName":@"ico_setting_pri_gx_wite"},@{@"titleName":@"收藏列表",@"subtitleName":@"开启隐私后，仅自己可见，其它人将不能访问收藏列表",@"imgName":@"ico_setting_pri_shoucang_wite"},@{@"titleName":@"喜欢列表",@"subtitleName":@"开启隐私后，仅自己可见，其它人将不能访问喜欢列表",@"imgName":@"ico_setting_pri_xihuan_wite"}];
    
    self.my_setting_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, KScreen_H-(kStatusBarHeight+44))];
    self.my_setting_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.my_setting_tableView.backgroundColor = viewback_black;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:self.my_setting_tableView];
    [self.my_setting_tableView registerNib:[UINib nibWithNibName:@"MyPrivacySettingCell" bundle:nil] forCellReuseIdentifier:@"MyPrivacySettingCell"];
    self.my_setting_tableView.delegate = self;
    self.my_setting_tableView.dataSource = self;
    self.my_setting_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _my_settingArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyPrivacySettingCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MyPrivacySettingCell"];
    cell.typeImage.image = KImageNamed(self.my_settingArr[indexPath.row][@"imgName"]);
    cell.typeTitle.text = self.my_settingArr[indexPath.row][@"titleName"];
    cell.typeTip.text = self.my_settingArr[indexPath.row][@"subtitleName"];
    if([self.my_settingArr[indexPath.row][@"titleName"] isEqualToString:@"关注和粉丝列表"]){
        cell.typeSwitch.on = [[QZUserInfoModel share].follow_permission boolValue];
    }else if ([self.my_settingArr[indexPath.row][@"titleName"] isEqualToString:@"喜欢列表"]){
        cell.typeSwitch.on = [[QZUserInfoModel share].like_permission boolValue];
    }else if ([self.my_settingArr[indexPath.row][@"titleName"] isEqualToString:@"收藏列表"]){
        cell.typeSwitch.on = [[QZUserInfoModel share].collect_permission boolValue];
    }
    cell.MyPrivacySettingBlock = ^{
        KMutableDic(sendDic)
        if(indexPath.row == 0){
            [sendDic setObject:@"follow_permission" forKey:@"name"];
            if([[QZUserInfoModel share].follow_permission intValue] == 1){
                [sendDic setObject:@(0) forKey:@"value"];
            }else{
                [sendDic setObject:@(1) forKey:@"value"];
            }
        }else if(indexPath.row == 1){
            [sendDic setObject:@"collect_permission" forKey:@"name"];
            if([[QZUserInfoModel share].collect_permission intValue] == 1){
                [sendDic setObject:@(0) forKey:@"value"];
            }else{
                [sendDic setObject:@(1) forKey:@"value"];
            }
        }else if(indexPath.row == 2){
            [sendDic setObject:@"like_permission" forKey:@"name"];
            if([[QZUserInfoModel share].like_permission intValue] == 1){
                [sendDic setObject:@(0) forKey:@"value"];
            }else{
                [sendDic setObject:@(1) forKey:@"value"];
            }
        }
        KWeakSelf
        [YBNetBase editPermissionRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                if(indexPath.row == 0){
                    if([[QZUserInfoModel share].follow_permission intValue] == 1){
                        [QZUserInfoModel share].follow_permission = @(0);
                    }else{
                        [QZUserInfoModel share].follow_permission = @(1);
                    }
                }else if(indexPath.row == 1){
                    if([[QZUserInfoModel share].collect_permission intValue] == 1){
                        [QZUserInfoModel share].collect_permission = @(0);
                    }else{
                        [QZUserInfoModel share].collect_permission = @(1);
                    }
                }else if(indexPath.row == 2){
                    if([[QZUserInfoModel share].like_permission intValue] == 1){
                        [QZUserInfoModel share].like_permission = @(0);
                    }else{
                        [QZUserInfoModel share].like_permission = @(1);
                    }
                }
            }else{
                [YBMsgPop showPop:msg];
            }
            [weakSelf.my_setting_tableView reloadData];
        }];
    };
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

@end
